home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mint110s / mem.h < prev    next >
C/C++ Source or Header  |  1994-02-02  |  6KB  |  207 lines

  1. /*
  2. Copyright 1990,1991,1992 Eric R. Smith.
  3. Copyright 1992,1993 Atari Corporation.
  4. All rights reserved.
  5. */
  6.  
  7. #ifndef _mem_h
  8. #define _mem_h
  9.  
  10. #include "file.h"
  11.  
  12. typedef struct memregion {
  13.     long    loc;        /* base of memory region */
  14.     ulong    len;        /* length of memory region */
  15.     ushort    links;        /* number of users of region */
  16.     ushort    mflags;        /* e.g. which map this came from */
  17.     struct memregion *next; /* next region in memory map */
  18. } MEMREGION;
  19.  
  20. /* flags for memory regions: these are used only in MEMREGION struct */
  21. #define M_CORE        0x01    /* region came from core map */
  22. #define M_ALT        0x02    /* region came from alt map */
  23. #define M_SWAP        0x04    /* region came from swap map */
  24. #define M_KER        0x08    /* region came from kernel map */
  25. #define M_MAP        0x0f    /* and with this to pick out map */
  26.  
  27. #define M_SHTEXT    0x10    /* region is a shared text region */
  28. #define M_KEEP        0x0100    /* don't free on process termination */
  29.  
  30. /* dummy type for virtual addresses */
  31. typedef struct vaddr {
  32.     char dummy;
  33. } *virtaddr;
  34.  
  35. /* structure for shared text regions */
  36.  
  37. typedef struct shtextreg {
  38.     FILEPTR *f;        /* what file did this come from? */
  39.     MEMREGION *text;    /* pointer to shared text region */
  40.     short mtime, mdate;    /* date & time for file */
  41.     struct shtextreg *next;
  42. } SHTEXT;
  43.  
  44. /*
  45.  * Here's the deal with memory bits:
  46.  *
  47.  * Mxalloc(long size, int mode) takes these fields in 'mode': BITS 0-2 hold
  48.  * values 0-3 for the old GEMDOS mode argument.  If bit 3 is on, then only
  49.  * F_PROTMODE (bits 4-7) counts, and it encodes the desired protection mode
  50.  * to change a block to. Else F_PROTMODE is the desired protection mode for
  51.  * the new block you're allocating.  In either case, F_PROTMODE turns into
  52.  * a PROT_* thusly: if it's zero, you get the F_PROTMODE value from curproc's
  53.  * prgflags. Else you get (F_PROTMODE >> F_PROTSHIFT)-1.
  54.  *
  55.  * The 0x4000 bit is carried along into get_region (but not from there into
  56.  * mark_region) and, if set, causes M_KEEP to be set in the region's
  57.  * mflags.
  58.  */
  59.  
  60. /* structure of exectuable program headers */
  61. typedef struct fileheader {
  62.     short    fmagic;
  63.     long    ftext;
  64.     long    fdata;
  65.     long    fbss;
  66.     long    fsym;
  67.     long    reserved;
  68.     long    flag;
  69.     short    reloc;
  70. } FILEHEAD;
  71.  
  72. #define GEMDOS_MAGIC 0x601a
  73.  
  74. /* flags for curproc->memflags */
  75. /* also used for program headers PRGFLAGS */
  76. #define F_FASTLOAD    0x01        /* don't zero heap */
  77. #define F_ALTLOAD    0x02        /* OK to load in alternate ram */
  78. #define F_ALTALLOC    0x04        /* OK to malloc from alt. ram */
  79. #define F_RESERVED    0x08        /* reserved for future use */
  80. #define F_MEMFLAGS    0xf0        /* reserved for future use */
  81. #define F_SHTEXT    0x800        /* program's text may be shared */
  82.  
  83. #define F_MINALT    0xf0000000L    /* used to decide which type of RAM to load in */
  84.  
  85. /* Bit in Mxalloc's arg for "don't auto-free this memory" */
  86. #define F_KEEP        0x4000
  87.  
  88. #define F_OS_SPECIAL    0x8000        /* mark as a special process */
  89.  
  90. /* flags for curproc->memflags (that is, PRGFLAGS) and also Mxalloc mode.  */
  91. /* (Actually, when users call Mxalloc, they add 0x10 to what you see here) */
  92. #define    F_PROTMODE    0xf0        /* protection mode bits */
  93. #define F_PROT_P    0x00        /* no read or write */
  94. #define F_PROT_G    0x10        /* any access OK */
  95. #define F_PROT_S    0x20        /* any super access OK */
  96. #define F_PROT_PR    0x30        /* any read OK, no write */
  97. #define F_PROT_I    0x40        /* invalid page */
  98.  
  99. /* actual values found in page_mode_table and used as args to alloc_region */
  100. #define PROT_P    0
  101. #define PROT_G    1
  102. #define PROT_S    2
  103. #define PROT_PR    3
  104. #define PROT_I    4
  105. #define PROT_MAX_MODE 4
  106. #define PROT_PROTMODE 0xf   /* these bits are the prot mode */
  107. #define PROT_NOCHANGE -1
  108.  
  109. #define F_PROTSHIFT    4
  110.  
  111. typedef MEMREGION **MMAP;
  112.  
  113. #ifndef GENMAGIC
  114. extern MMAP core, alt, ker, swap;
  115. #endif
  116.  
  117. /* compilers differ on what "sizeof" returns */
  118. #define SIZEOF        (long)sizeof
  119.  
  120. /* QUANTUM: the page size for the mmu: 8K.  This is hard-coded elsewhere. */
  121. #define QUANTUM 0x2000L
  122.  
  123. /* MiNT leaves this much memory for TOS to use (8K)
  124.  */
  125. #define TOS_MEM        (QUANTUM)
  126.  
  127. /* MiNT tries to keep this much memory available for the kernel and other
  128.  * programs when a program is launched (8K)
  129.  */
  130. #define KEEP_MEM    (QUANTUM)
  131.  
  132. /*
  133.  * how much memory should be allocated to the kernel? (24K)
  134.  */
  135. #define KERNEL_MEM    (3*QUANTUM)
  136.  
  137. /* macro for rounding off region sizes to QUANTUM (page) boundaries */
  138. /* there is code in mem.c that assumes it's OK to put the screen
  139.  * in any region, so this should be at least 256 for STs (16 is OK for
  140.  * STes, TTs, and Falcons). We actually set a variable in main.c
  141.  * that holds the screen boundary stuff.
  142.  */
  143. extern int no_mem_prot;
  144. extern int screen_boundary;
  145.  
  146. #define MASKBITS    (no_mem_prot ? screen_boundary : (QUANTUM-1))
  147. #define ROUND(size) ((size + MASKBITS) & ~MASKBITS)
  148.  
  149. /* interesting memory constants */
  150.  
  151. #define EIGHT_K (0x400L*8L)
  152. #define ONE_MEG 0x00100000L
  153. #define LOG2_ONE_MEG 20
  154. #define LOG2_16_MEG 24
  155. #define LOG2_EIGHT_K 13
  156. #define SIXTEEN_MEG (0x400L*0x400L*16L)
  157.  
  158. /* macro for turning a curproc->base_table pointer into a 16-byte boundary */
  159. #define ROUND16(ld) ((long_desc *)(((ulong)(ld) + 15) & ~15))
  160.  
  161. /* TBL_SIZE is the size in entries of the A, B, and C level tables */
  162. #define TBL_SIZE (16)
  163. #define TBL_SIZE_BYTES (TBL_SIZE * sizeof(long_desc))
  164.  
  165. typedef struct {
  166.     short limit;
  167.     unsigned zeros:14;
  168.     unsigned dt:2;
  169.     struct long_desc *tbl_address;
  170. } crp_reg;
  171.  
  172. /* format of long descriptors, both page descriptors and table descriptors */
  173.  
  174. typedef struct {
  175.     unsigned limit;        /* set to $7fff to disable */
  176.     unsigned unused1:6;
  177.     unsigned unused2:1;
  178.     unsigned s:1;        /* 1 grants supervisor access only */
  179.     unsigned unused3:1;
  180.     unsigned ci:1;        /* cache inhibit: used in page desc only */
  181.     unsigned unused4:1;
  182.     unsigned m:1;        /* modified: used in page desc only */
  183.     unsigned u:1;        /* accessed */
  184.     unsigned wp:1;        /* write-protected */
  185.     unsigned dt:2;        /* type */
  186. } page_type;
  187.  
  188. typedef struct long_desc {
  189.     page_type page_type;
  190.     struct long_desc *tbl_address;
  191. } long_desc;
  192.  
  193. typedef struct {
  194.     unsigned enable:1;
  195.     unsigned zeros:5;
  196.     unsigned sre:1;
  197.     unsigned fcl:1;
  198.     unsigned ps:4;
  199.     unsigned is:4;
  200.     unsigned tia:4;
  201.     unsigned tib:4;
  202.     unsigned tic:4;
  203.     unsigned tid:4;
  204. } tc_reg;
  205.  
  206. #endif /* _mem_h */
  207.